layui.use(['layer', 'util'], function () {
    let layer = layui.layer;
    var util = layui.util;
    document.addEventListener('click', function (event) {
        const target = event.target;
        if (target.tagName.toLowerCase() === 'img' && !target.classList.contains('layer_img')) {
            const imgSrc = target.src;
            layer.open({
                type: 1,
                title: false,
                closeBtn: 1,
                shadeClose: true,
                area: 'auto',
                shade: 0.6,
                scrollbar: false,
                skin: 'layui-layer-nobg',
                content:
                    '<div><img class="layer_img" src="' +
                    imgSrc +
                    '" style="max-width:100%;max-height:100%;" /></div>',
            });
        }
    });

    // 固定条组件 https://layui.dev/docs/2/fixbar/#fixbar
    util.fixbar({
        bars: [{
            type: 'cart',
            icon: 'layui-icon-cart',
            style: 'background-color: #FF5722;'
        }, {
            type: 'group',
            content: '群',
            style: 'font-size: 21px;'
        }]
        // 任意事件
        , on: {
            mouseenter: function (type) {
                layer.tips(type, this, {tips: 4, fixed: true});
            },
            mouseleave: function (type) {
                layer.closeAll('tips');
            }
        }
        // 点击事件
        , click: function (type) {
            switch (type) {
                case 'group':
                    layer.open({
                        type: 1,
                        title: 'Q Q 群',     //不显示标题栏
                        closeBtn: false,
                        area: '300px;',
                        shade: 0.8,
                        id: 'LAY_layuipro', //设定一个id，防止重复弹出
                        btn: ['确定'],
                        btnAlign: 'c',
                        moveType: 1,    //拖拽模式，0或者1
                        content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">859882209 41477250<br><br>924099912 871899361</div>'
                    });
                    break;
                case 'cart':
                    window.open('https://iyuu.cn/service_item', '_blank');
                    break;
                default:
                    break;
            }
        }
    });
});
